﻿<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Add View Audit Log item to Site Actions menu -->
  <CustomAction
    Id="SiteActionsToolbar"
    GroupId="SiteActions"
    Location="Microsoft.SharePoint.StandardMenu"
    Sequence="400"
    Title="View Audit Log"
    Description="View the audit log for this site."
    ImageUrl="~site/_layouts/SharePointStu.ItemAuditing/Images/audit.gif"
    Rights="EditListItems">
    <UrlAction Url="javascript: if (confirm('Please note that you can consult the log at the level of item or list. A site level audit log may take an extensive amount of time. Continue?')) { window.location= '{SiteUrl}/_layouts/SharePointStu.ItemAuditing/ViewWebAuditLog.aspx?CancelSource=' + escape(window.location) }"/>
  </CustomAction>

  <!-- Add View Audit Log item to the ribbon -->
  <CustomAction
    Id="SharePointStu.Ribbon.Lists.ViewAudit"
    Location="CommandUI.Ribbon" RegistrationType="ContentType" RegistrationId="0x">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Library.Actions.Controls._children">
          <Button
            Id="SharePointStu.Ribbon.Documents.Manage.ViewListAuditLog"
            Sequence="5"
            Command="SharePointStu.PageComponent.Command.ViewListAuditLog"
            Image16by16="/_layouts/SharePointStu.ItemAuditing/Images/audit.gif"
            Image32by32="/_layouts/SharePointStu.ItemAuditing/Images/audit.gif"
            LabelText="View Audit Log"
            ToolTipTitle="View the audit log for this list"
            ToolTipDescription="View the audit log for this list"
            TemplateAlias="o1" />
        </CommandUIDefinition>
        <CommandUIDefinition
          Location="Ribbon.List.Actions.Controls._children">
          <Button
            Id="SharePointStu.Ribbon.Documents.Manage.ViewListAuditLog"
            Sequence="5"
            Command="SharePointStu.PageComponent.Command.ViewListAuditLog"
            Image16by16="/_layouts/SharePointStu.ItemAuditing/Images/audit.gif"
            Image32by32="/_layouts/SharePointStu.ItemAuditing/Images/audit.gif"
            LabelText="View Audit Log"
            ToolTipTitle="View the audit log for this list"
            ToolTipDescription="View the audit log for this list"
            TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="SharePointStu.PageComponent.Command.ViewListAuditLog"
          CommandAction="javascript:window.location= '{SiteUrl}/_layouts/SharePointStu.ItemAuditing/ViewListAuditLog.aspx?ListId={ListId}&amp;CancelSource=' + escape(window.location)"
        />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

  <!-- Add View Audit Log item to the ribbon -->
  <CustomAction
    Id="SharePointStu.Ribbon.Documents.ViewAudit"
    Location="CommandUI.Ribbon" RegistrationType="ContentType" RegistrationId="0x">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Documents.Manage.Controls._children">
          <Button
            Id="SharePointStu.Ribbon.Documents.Manage.ViewListItemAuditLog"
            Sequence="5"
            Command="SharePointStu.PageComponent.Command.ViewListItemAuditLog"
            Image16by16="/_layouts/SharePointStu.ItemAuditing/Images/audit.gif"
            Image32by32="/_layouts/SharePointStu.ItemAuditing/Images/audit.gif"
            LabelText="View Audit Log"
            ToolTipTitle="View the audit log for this item"
            ToolTipDescription="View the audit log for this item"
            TemplateAlias="o1" />
        </CommandUIDefinition>
        <CommandUIDefinition
          Location="Ribbon.ListItem.Manage.Controls._children">
          <Button
            Id="SharePointStu.Ribbon.Documents.Manage.ViewListItemAuditLog"
            Sequence="5"
            Command="SharePointStu.PageComponent.Command.ViewListItemAuditLog"
            Image16by16="/_layouts/SharePointStu.ItemAuditing/Images/audit.gif"
            Image32by32="/_layouts/SharePointStu.ItemAuditing/Images/audit.gif"
            LabelText="View Audit Log"
            ToolTipTitle="View the audit log for this item"
            ToolTipDescription="View the audit log for this item"
            TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="SharePointStu.PageComponent.Command.ViewListItemAuditLog"
          CommandAction="javascript:
            var clientContext = SP.ClientContext.get_current();
            var items = SP.ListOperation.Selection.getSelectedItems(clientContext);
            if (items.length === 1) {
              window.location= '{SiteUrl}/_layouts/SharePointStu.ItemAuditing/ViewItemAuditLog.aspx?ListId=' + SP.ListOperation.Selection.getSelectedList() + '&amp;ItemId=' + items[0].id + '&amp;CancelSource=' + escape(window.location)
            }"
          EnabledScript="javascript:
            function isAuditEnabledForItem() {
              var clientContext = SP.ClientContext.get_current();
              var items = SP.ListOperation.Selection.getSelectedItems(clientContext);
              if (items.length === 1)
                return true;
              else
                return false;
            };
            isAuditEnabledForItem();"
        />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
  
  <!-- Add View Audit Log item to ECB menu -->
  <CustomAction
    Id="ECBItem_ViewAuditLog"
    Rights="EditListItems"
    RegistrationType="ContentType"
    RegistrationId="0x"
    Location="EditControlBlock"
    Sequence="300"
    GroupId="ECBItem"
    ImageUrl="~site/_layouts/SharePointStu.ItemAuditing/Images/audit.gif"
    Title="View Audit Log"
    Description="View the audit log for this item.">
    <UrlAction Url="javascript:window.location= '{SiteUrl}/_layouts/SharePointStu.ItemAuditing/ViewItemAuditLog.aspx?ListId={ListId}&amp;ItemId={ItemId}&amp;CancelSource=' + escape(window.location)"/>
  </CustomAction>
</Elements>
